﻿-- Function: pl_function.listar_predios(character varying, character varying, refcursor)

-- DROP FUNCTION pl_function.listar_predios(character varying, character varying, refcursor);

CREATE OR REPLACE FUNCTION pl_function.listar_predios(p_mhresum character varying, p_cidpers character varying, p_ref refcursor)
  RETURNS refcursor AS
$BODY$
begin
	open p_ref for select a.ccodpre
		, a.tnumero
		, a.vusogen
		, a.viconos
		, a.cusogen
		, a.nterren
		, a.narance
		, a.nvalter
		, a.nvalpis
		, a.nvalins
		, a.nvalpre
		, a.nporafe
		, a.nvalafe
		, a.dfecadq
		, a.vnrodoc
		, a.nporcen
		, a.mpredio
		, a.dpredio
		, a.tnompob
		, a.tnomvia
		, a.dnumero
		, a.ddepart
		, a.dmanzan
		, a.dnlotes
		, a.mhresum
		, a.cperiod
		, a.pestado
		, a.mestado
		, a.destado
		from pl_select.listar_predios(p_mhresum, p_cidpers) a
		order by a.destado desc, a.mpredio;
	return p_ref;
end
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION pl_function.listar_predios(character varying, character varying, refcursor)
  OWNER TO postgres;
GRANT EXECUTE ON FUNCTION pl_function.listar_predios(character varying, character varying, refcursor) TO postgres;
GRANT EXECUTE ON FUNCTION pl_function.listar_predios(character varying, character varying, refcursor) TO public;
GRANT EXECUTE ON FUNCTION pl_function.listar_predios(character varying, character varying, refcursor) TO desarrollo;